package cn.by.wms.listenner;

import cn.by.wms.App;
import cn.by.wms.dto.InventoryOptionDTO;
import cn.by.wms.event.InventoryOptionEvent;
import cn.by.wms.service.InventoryService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;

public class InventoryListener
        implements ApplicationListener<InventoryOptionEvent>, ApplicationContextAware{
    private ApplicationContext applicationContext;
    @Override
    public void onApplicationEvent(InventoryOptionEvent event) {
        InventoryOptionDTO inventoryOptionDTO = (InventoryOptionDTO) (event.getSource());
        InventoryService bean = applicationContext.getBean(InventoryService.class);
        bean.process(inventoryOptionDTO);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
